package com.syy.partition;

import com.syy.flow.FlowBean;
import com.syy.flow.FlowMapper;
import com.syy.flow.FlowReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class FlowPartitionDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);

        job.setJarByClass(FlowPartitionDriver.class);
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);


        // 如果分区了，要设置对应的reduce数量
        job.setNumReduceTasks(5);
        // 设置自定义分区
        job.setPartitionerClass(FlowPartition.class);




        FileInputFormat.setInputPaths(job, new Path("F:\\projects\\JavaProjects\\myproject\\JavaProjects\\MapReduceDemo\\src\\main\\resources\\input1\\phone_data.txt"));
        FileOutputFormat.setOutputPath(job, new Path("F:\\projects\\JavaProjects\\myproject\\JavaProjects\\MapReduceDemo\\src\\main\\resources\\output2"));

        boolean b = job.waitForCompletion(true);
        System.out.println(b ? "成功" : "失败");


    }
}
